<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>样品单信息</legend>
            <div class="layui-form layuimini-form">

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="id" id="id" style="display: none"
                               class="layui-input">
                        <label class="layui-form-label required">样品单名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="sampleName" id="sampleName" lay-verify="required"
                                   value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label required">样品单编号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="sampleNo" id="sampleNo" lay-verify="required"
                                   value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label required">工厂</label>
                        <div class="layui-input-inline">
                            <select name="supplierId" id="supplierId" lay-verify="required" lay-search="">
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">客人货号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="customerItemsNo" id="customerItemsNo"
                                   value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">公司经办人</label>
                        <div class="layui-input-inline">
                            <input type="text" name="handler" id="handler"
                                   value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">交期</label>
                        <div class="layui-input-inline">
                            <input readonly="readonly" type="text" class="layui-input" name="deliveryDate"
                                   id="deliveryDate">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">报价日期</label>
                        <div class="layui-input-inline">
                            <input readonly="readonly" type="text" class="layui-input" name="sampleDate"
                                   id="sampleDate">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">签字日期</label>
                        <div class="layui-input-inline">
                            <input readonly="readonly" type="text" class="layui-input" name="signatureDate"
                                   id="signatureDate">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">工厂地址</label>
                        <div class="layui-input-inline">
                            <input type="text" name="supplierAddress" id="supplierAddress"
                                   value="" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">工厂联系人</label>
                        <div class="layui-input-inline">
                            <input type="text" name="supplierContacts" id="supplierContacts"
                                   value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">工厂经办人</label>
                        <div class="layui-input-inline">
                            <input type="email" name="supplierHandler" id="supplierHandler" value=""
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">工厂手机</label>
                        <div class="layui-input-inline">
                            <input type="text" name="supplierPhone" id="supplierPhone" value=""
                                   class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">工厂签字日期</label>
                        <div class="layui-input-inline">
                            <input readonly="readonly" type="text" class="layui-input" name="supplierSignatureDate"
                                   id="supplierSignatureDate">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
            </div>
        </fieldset>
    </div>
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="/static/js/common.js"></script>
<script>
    let ids = $.common.getUrlParam("ids");
    ids  = decodeURIComponent(ids);
    layui.use(['form', 'laydate'], function () {
        var form = layui.form,
            laydate = layui.laydate;
        //初始化时间
        laydate.render({
            elem: '#deliveryDate'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#sampleDate'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#signatureDate'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#supplierSignatureDate'
            , type: 'datetime'
        });

        //工厂
        let callback1 = {
            onSuccess: function (result) {
                if (result.code == '0') {
                    $('#supplierId').append(new Option('请选择', '', true));// 下拉菜单里添加元素
                    $.each(result.data, function (index, item) {
                        let option = new Option(item.supplierName, item.id);
                        $('#supplierId').append(option);// 下拉菜单里添加元素
                    });
                } else {
                    $.common.showErrorMessage(result.message)
                    return false;
                }
            }
        };
        $.xAjax('/supplier/select', 'POST', JSON.stringify({}), callback1);
        //初始化下拉框
        form.render("select");
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let url = "/sample/saveOrUpdate"
            let callback = {
                onSuccess: function (result) {
                    if (result.code == '0') {
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(iframeIndex);
                    } else {
                        $.common.showErrorMessage(result.message)
                        return false;
                    }
                }
            };
            data.field.itemIds=JSON.parse(ids);
            $.xAjax(url, 'POST', JSON.stringify(data.field), callback);
            return false;
        });
    });

</script>
</body>
</html>
